package com.ruoyi.distributionGrade.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.distributionGrade.domain.DistributionGrade;
import com.ruoyi.distributionGrade.service.IDistributionGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销等级Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/distributionGrade")
public class DistributionGradeController extends BaseController
{
    @Autowired
    private IDistributionGradeService distributionGradeService;

    /**
     * 查询分销等级列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionGrade distributionGrade)
    {
        startPage();
        List<DistributionGrade> list = distributionGradeService.selectDistributionGradeList(distributionGrade);
        return getDataTable(list);
    }

    /**
     * 导出分销等级列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:export')")
    @Log(title = "分销等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionGrade distributionGrade)
    {
        List<DistributionGrade> list = distributionGradeService.selectDistributionGradeList(distributionGrade);
        ExcelUtil<DistributionGrade> util = new ExcelUtil<DistributionGrade>(DistributionGrade.class);
        util.exportExcel(response, list, "分销等级数据");
    }

    /**
     * 获取分销等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(distributionGradeService.selectDistributionGradeByGradeId(gradeId));
    }

    /**
     * 新增分销等级
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:add')")
    @Log(title = "分销等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionGrade distributionGrade)
    {
        return toAjax(distributionGradeService.insertDistributionGrade(distributionGrade));
    }

    /**
     * 修改分销等级
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:edit')")
    @Log(title = "分销等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionGrade distributionGrade)
    {
        return toAjax(distributionGradeService.updateDistributionGrade(distributionGrade));
    }

    /**
     * 删除分销等级
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:distributionGrade:remove')")
    @Log(title = "分销等级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(distributionGradeService.deleteDistributionGradeByGradeIds(gradeIds));
    }
}
